<!doctype html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>天天兼职</title>
    <link rel="stylesheet" type="text/css" href="./css/api.css"/>
    <link rel="stylesheet" type="text/css" href="./css/style.css"/>
    <style>
        header{ background-color: #fff;  }
        header ul li { height: 0; text-align: center; display: none; color: #939393; position: relative;font-size: 0;  }
        header ul li.active{ display: none; }
        #footer{  background-color: #fff;height: 45px}
        #footer ul{display: flex;height: 45px}
        #footer ul li{ padding-top: 27px;background: url() no-repeat center 6px; background-size: auto 19px; text-align: center;font-size: 10px; }
        #footer ul li.active{ color: #000; }
        #footer ul li:nth-child(1){ background-image: url(./image/bottombtn0101.png); }
        #footer ul li:nth-child(2){ background-image: url(./image/bottombtn0201.png); }
        #footer ul li:nth-child(3){ background-image: url(./image/bottombtn0301.png); }
        #footer ul li:nth-child(4){ background-image: url(./image/bottombtn0401.png); }
        #footer ul li:nth-child(1).active{ background-image: url(./image/bottombtn0102.png); }
        #footer ul li:nth-child(2).active{ background-image: url(./image/bottombtn0202.png); }
        #footer ul li:nth-child(3).active{ background-image: url(./image/bottombtn0302.png); }
        #footer ul li:nth-child(4).active{ background-image: url(./image/bottombtn0402.png); }
        .flex-con{
          overflow: auto
        }
    </style>
</head>
<body>
<div id="wrap" class="flex-wrap flex-vertical">
    <header>
        <ul>
            <li class="border-b" ></li>
            <li class="border-b" ></li>
            <li class="border-b" ></li>
            <li class="border-b" ></li>
        </ul>
    </header>
    <div id="main" class="flex-con">

    </div>
    <div id="footer" class="border-t">
        <ul class="flex-wrap" >
            <li tapmode="hover" onclick="randomSwitchBtn( this );" class="flex-con active" >首页</li>
            <li tapmode="hover" onclick="randomSwitchBtn( this );" class="flex-con" >发现</li>
            <li tapmode="hover" onclick="randomSwitchBtn( this );" class="flex-con" >消息</li>
            <li tapmode="hover" onclick="randomSwitchBtn( this );" class="flex-con" >我的</li>
        </ul>
    </div>
</div>
</body>
</html>
<script type="text/javascript" src="script/api.js"></script>
<script type="text/javascript" src="script/encrypt.js"></script>
<script type="text/javascript">
    apiready = function () {
        $api.fixTabBar($api.byId('footer'))
        api.setStatusBarStyle({
            style: 'dark'
        });
        funIniGroup();
        var appVersion = api.appVersion;

        var base = new Base64();
        var userid = $api.getStorage('userID');
        let json;
        if(userid){
          json = {userID:userid}
        }else{
          json = {userID:'00000000-0000-0000-0000-000000000000'}
        }
        var parameter = base.encode(JSON.stringify(json));
        var signValue = parameter + secretKey
        var sign = signValue.MD5(32);
        var downurl = ''
        $api.post(url+'getAppParameters.ashx', {values:{parameter:parameter,sign:sign}}, function(ret){


          if(ret.code == 200){

            for(var i =0,iL=ret.data.ParamList.length;i<iL;i++){

              if(ret.data.ParamList[i].paraName == 'APP_UPGRADE_LINK'){
                downurl = ret.data.ParamList[i].paraValue;

              }

              if(ret.data.ParamList[i].paraName == 'APP_CURRENT_VERSION'){

                var versionValue = ret.data.ParamList[i].paraValue
                $api.setStorage('version', versionValue);
                var oldVersion = 1 + appVersion.split('.')[0] + appVersion.split('.')[1] + appVersion.split('.')[2];
                var newVersion = 1 + versionValue.split('.')[0] + versionValue.split('.')[1] +versionValue.split('.')[2]

                if(!( Number(oldVersion) >=  Number(newVersion) )){
                  api.confirm({
                         title : '有新版本，请下载更新',
                         msg : '当前版本'+appVersion +'，最新版本'+ret.data.ParamList[i].paraValue,
                         buttons : ['确定', '取消']
                     },function(ret,err){
                       if(ret.buttonIndex == 1){

                         if(api.systemType == "android"){
                           api.openApp({
                             androidPkg: 'android.intent.action.VIEW',
                             mimeType: 'text/html',
                             uri: downurl
                           });
                         }if(api.systemType == "ios"){
                           api.openApp({
                              iosUrl: downurl,
                          });
                         }

                       }
                     })

                }
              }
            }

          }else{
            alert(ret.msg)
          }
        })

    }

    function funIniGroup(){
        var eHeaderLis = $api.domAll('header li'),
            frames = [];
        for (var i = 0,len = eHeaderLis.length; i < len; i++) {
                frames.push( {
                    name: 'frame'+i,
                    url: './html/frame'+i+'.html',
                    bgColor : 'rgba(255,255,255,0)',
                    bounces:false
                } )
        }
        api.openFrameGroup({
            name: 'group',
            scrollEnabled: false,
            rect: {
                x: 0,
                y: $api.dom('header').offsetHeight ,
                w: api.winWidth,
                h: $api.dom('#main').offsetHeight
            },
            index: 0,
            frames: frames
        }, function (ret, err) {

        });
    }

    // 随意切换按钮
    function randomSwitchBtn( tag ) {
        if( tag == $api.dom('#footer li.active') )return;
        var eFootLis = $api.domAll('#footer li'),
            eHeaderLis = $api.domAll('header li'),
            index = 0;
        for (var i = 0,len = eFootLis.length; i < len; i++) {
            if( tag == eFootLis[i] ){
                index = i;
            }else{
                $api.removeCls(eFootLis[i], 'active');
                $api.removeCls(eHeaderLis[i], 'active');
            }
        }
        $api.addCls( eFootLis[index], 'active');
        $api.addCls( eHeaderLis[index], 'active');
        api.setFrameGroupIndex({
            name: 'group',
            index: index,
            // reload:true
        });
    }
</script>
